let util = require('util');
let mysqlPool = require('./MySQLPool');

class ClubCardsUpdateRecordDao {
    constructor() {
    }

    /**
     * 
     * @param {{club_id: String, c_uid: String, cards: Number, type: String, remark: String}} ClubCardsUpdateRecord 
     */

    async save(ClubCardsUpdateRecord){
    let sql = 'insert into club_cards_update_record (club_id, c_uid, cards, type, remark, name, headimgurl, create_time, update_time)' +
        '                           values          (?,       ?,     ?,     ?,    ?,     ?,      ?,         now(),       now())';
        let args = [ClubCardsUpdateRecord.clubId, ClubCardsUpdateRecord.uid, ClubCardsUpdateRecord.cards, ClubCardsUpdateRecord.type, ClubCardsUpdateRecord.remark, ClubCardsUpdateRecord.name, ClubCardsUpdateRecord.headimgurl];
        let res = await mysqlPool.query(sql, args);
        if (res) {
            return res.insertId;
        }

        return 0;
    }

    //查询基金清单
    async GetBill(uid,clubID,page){
        let pageNum = 0;
        if (page) {
            pageNum = page * 20;
        }
        let sql = 'select * from club_cards_update_record where club_id=? and c_uid=? and type=? order by create_time desc limit ?,?';
        let args = [clubID,uid,"CLUB_UPDATE",pageNum,20];
        let res = await mysqlPool.query(sql, args);
        if (res) {
            return res;
        }
        return null;
    }
}

let clubCardsUpdateRecordDao = new ClubCardsUpdateRecordDao();
module.exports = clubCardsUpdateRecordDao;